var cards = {}
cards.Game = {}
cards.Game.cardWidth = 180;
cards.Game.cardHeight = 240;
cards.Game.deck =
    [
        'Liu', 'Liu',
        'Guan', 'Guan',
        'Zhang', 'Zhang',
        'Yun', 'Yun',
        'Ma', 'Ma',
        'Huang', 'Huang',
    ]
function shuffle() {
    //Math.random能返回0~1之间的数
    //随机数大于0.5取-1，否则是1
    return Math.random() > 0.5 ? -1 : 1
}
function selected() {
    var open = $('.fadeOut')
    //点击两次结束
    if (open.length > 1) {
        return
    }
    $(this).find('.gcards').addClass('animated fadeOut')
    var opens=$('.fadeOut')   
    if(opens.length==2){
          setTimeout(function(){
           lookCard(opens.siblings())
          },700)
    }
}
function lookCard(cards){ 
    var mark1 = $(cards[0]).attr('class')
    var mark2 = $(cards[1]).attr('class')
    if(mark1 == mark2){
        $(cards).parent().remove()
    }
    else{
        $(cards).siblings().removeClass('animated fadeOut')
    }
}
$(function () {
    cards.Game.deck.sort(shuffle)
    var abc = $('.abc')
    for (var i = 0; i < 11; i++) {
        abc.clone().appendTo($('main'))
    }
    $(".abc").each(function (index) {
        $(this).css({
            "left": (cards.Game.cardWidth + 20) * (index % 4) + 'px',
            "top": (cards.Game.cardHeight + 20) * Math.floor(index / 4) + "px"
        })
        var mark = cards.Game.deck.pop()
        console.log(mark)        
        $(this).find('.cards').addClass(mark)
        $(this).click(selected)
    })
})